#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<assert.h>

#define FILE_NAME "TextSystem.txt"

#define ONE   (1 << 0)
#define TWO   (1 << 1)
#define THREE (1 << 2)
#define FOUR  (1 << 3)
#define FIVE  (1 << 4)


void Option(int flags)
{
     if(flags & ONE) printf("ONE\n");
     if(flags & TWO) printf("TWO\n");
     if(flags & THREE) printf("THREE\n");
     if(flags & FOUR) printf("FOUR\n");
     if(flags & FIVE) printf("FIVE\n");
     
}


//今天学习文件操作之系统调用接口
int main()
{
   //把默认权限码设为0 
    umask(0);   
    // O_CREAT 和 O_WRONLY 表示 标位符，每个标位符对应不同的含义
    int fd =  open(FILE_NAME , O_CREAT | O_WRONLY   , 0666);
    assert(fd != -1);
    
    Option(ONE | FIVE);
    printf("我的文件标识符:%d\n", fd);

    char buffer[] = "测试系统调用write\n";
    ssize_t ret = write(fd,buffer,sizeof(buffer)-1);
    if(ret == sizeof(buffer)-1)
    {
       printf("write写入成功\n");
    }


    close(fd);


    return 0;
}
